﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CustomWindow;

namespace Pawing.Controls.Emotions
{
    /// <summary>
    /// EmotionBoard.xaml 的交互逻辑
    /// </summary>
    public partial class EmotionsBoard
    {
        public EmotionsBoard()
        {
            InitializeComponent();
            this.MinimizeButtonState = WindowButtonState.None;
            this.MaximizeButtonState = WindowButtonState.None;
            foreach (var item in MainWindow.EmotionDictionary)
            {
                FlipTile3D.FlipTile3D ft = new FlipTile3D.FlipTile3D(item.Value);
                ft.EmotionClick += new RoutedEventHandler(FlipTile3D_Click);
                Tabs.Items.Add(new TabItem()
                {
                    Header = (item.Key == "") ? "默认" : item.Key,
                    Content = ft
                });
            }
        }


        protected override Decorator GetWindowButtonsPlaceholder()
        {
            return WindowButtonsPlaceholder;
        }

        public static readonly RoutedEvent EmotionClickedEvent = EventManager.RegisterRoutedEvent(
            "EmotionClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(EmotionsBoard));

        public event RoutedEventHandler EmotionClicked
        {
            add { AddHandler(EmotionClickedEvent, value); }
            remove { RemoveHandler(EmotionClickedEvent, value); }
        }

        private void FlipTile3D_Click(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new RoutedEventArgs(EmotionClickedEvent, e.OriginalSource));
        }

        private Point lastPosition;
        private void HeaderPanel_MouseMove(object sender, MouseEventArgs e)
        {
            WrapPanel wp = (WrapPanel)sender;
            ScrollViewer sv = (ScrollViewer)wp.Parent;
            if (lastPosition == null)
            {
                lastPosition = e.GetPosition(this);
            }
            else
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    sv.ScrollToHorizontalOffset(sv.HorizontalOffset - e.GetPosition(this).X + lastPosition.X);
                }
                lastPosition = e.GetPosition(this);
            }
        }

        private void Grid_MouseEnter(object sender, MouseEventArgs e)
        {
        }

        private void Grid_MouseLeave(object sender, MouseEventArgs e)
        {

        }

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                this.DragMove();
        }
    }
}
